<?php

namespace App\Exceptions;

use Exception;
use Illuminate\Contracts\Auth\Authenticatable;
use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
use Illuminate\Http\Response;
use Symfony\Component\HttpKernel\Exception\HttpException;

class Handler extends ExceptionHandler
{
    /**
     * A list of the exception types that are not reported.
     *
     * @var array
     */
    protected $dontReport = [
        //
    ];

    /**
     * A list of the inputs that are never flashed for validation exceptions.
     *
     * @var array
     */
    protected $dontFlash = [
        'password',
        'password_confirmation',
    ];

    /**
     * Register the exception handling callbacks for the application.
     *
     * @return void
     */
    public function register()
    {
        $this->reportable(function (Throwable $e) {
            //
        });
    }
//    public function report(Exception $exception)
//    {
//        parent::report($exception);
//    }
//    public function render($request, Exception $exception)
//    {
//        if ($request->ajax() && $exception instanceof HttpException) {
//            $message = $exception->getMessage();
//            $status_code = $exception->getStatusCode();
//            return new Response(compact('message','status_code'),$status_code);
//        }
//        return parent::render($request, $exception);
//    }
    public function boot(){
        // 将所有的 Exception 全部交给 App\Exceptions\Handler 来处理
        app('api.exception')->register(function (Exception $exception) {
            $request = Illuminate\Http\Request::capture();
            return app('App\Exceptions\Handler')->render($request, $exception);
        });
    }


}
